package com.shire.bajocontrolredial.utils;

import java.lang.ref.WeakReference;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;

import com.shire.bajocontrolredial.BajoControlRedialActivity;

/**
 * @author yhernandezdiaz
 */
public class MyReceiver extends BroadcastReceiver {
	private final WeakReference<BajoControlRedialActivity> contextRef;

	public MyReceiver(BajoControlRedialActivity context) {
		super();
		this.contextRef = new WeakReference<BajoControlRedialActivity>(context);
		Log.d(BajoControlRedialActivity.TAG, "Receiver created");
	}

	@Override
	public void onReceive(Context context, Intent intent) {
		final Bundle extras = intent.getExtras();
		if (null != extras) {
			if (TelephonyManager.EXTRA_STATE_IDLE.equals(extras.getString(TelephonyManager.EXTRA_STATE)))
				this.contextRef.get().callStateIdle();
		}
	}

}
